package com.help10000.rms.ui.adapter

import android.app.AlertDialog
import android.content.Context
import android.content.Intent
import android.view.View
import com.amir.common.beans.OrderItem
import com.amir.common.holder.CommonViewHolder
import com.amir.common.mvp.base.BaseRecyclerAdapter
import com.amir.common.utils.DialoghintUtils
import com.amir.common.utils.DialoghintUtils.ButtonOnClickListener
import com.help10000.rms.R
import com.help10000.rms.ui.activitys.OrderDetailActivity


class RobOrderAdapter(
    context: Context?,
    dataList: List<OrderItem?>?,
    layoutId: Int
) : BaseRecyclerAdapter<OrderItem?>(context, dataList, layoutId) {
    override fun bindData(holder: CommonViewHolder?, data: OrderItem?, position: Int) {
        holder?.setViewVisibility(
            R.id.tv_roborder,
            if (data?.Buttons?.ShowQiangDan!!) View.VISIBLE else View.GONE
        )
//        val repairInfo = data?.RepairInfo
//        holder?.setText(R.id.tv_date, "${repairInfo?.AppointmentTime!!}")
//        holder?.setText(R.id.tv_num, text = "${position + 1}")
//        holder?.setText(R.id.tv_price, text = "${repairInfo?.VirtCharge}")
//        holder?.setText(R.id.tv_orderno, text = "${repairInfo?.RepairId}")
//        holder?.setText(R.id.tv_nameTel, text = "${repairInfo?.CustName}  ${repairInfo?.Tel}")
//        holder?.setText(
//            R.id.tv_address,
//            text = " ${repairInfo?.ProvName}${repairInfo?.CityName}${repairInfo?.TownName}${repairInfo?.Zone5}"
//        )
//        holder?.setText(R.id.tv_companyname, text = "${repairInfo?.CmpyName}")
//        holder?.setText(R.id.tv_status, text = "${repairInfo?.Status}")
//        holder?.setText(R.id.tv_desc, text = "${repairInfo?.CallDescr}")
//
//        holder?.setOnClickListener(R.id.tv_nameTel, View.OnClickListener {
//            if (!repairInfo?.CanTel!!) {
//
//                return@OnClickListener
//            }
//            val dialIntent = Intent(
//                Intent.ACTION_DIAL,
//                Uri.parse("tel:${repairInfo?.Tel}")
//            ) //跳转到拨号
//            mContext.startActivity(dialIntent)
//        })
        holder?.setOnClickListener(
            R.id.tv_roborder,
            View.OnClickListener { v: View? ->
                DialoghintUtils()
                    .init(mContext)
                    .setContent("确定抢单？")
                    .setAff(R.string.aff)
                    .setClose(R.string.close)
                    .setOnclick(object : ButtonOnClickListener {
                        override fun close(alertDialog: AlertDialog) {}
                        override fun aff(alertDialog: AlertDialog) {

                            if (robOrderInterface != null) {

                                robOrderInterface.robOrder(position);
                            }

                        }
                    }).show()
            }
        )
        holder?.setOnClickListener(
            R.id.ll_root,
            View.OnClickListener {
                val intent = Intent(
                    mContext,
                    OrderDetailActivity::class.java
                )
              // intent.putExtra("RepairId", "${repairInfo?.RepairId}")
//                mContext.startActivity(intent)
            })
    }

    lateinit var robOrderInterface: RobOrderInterface;

    interface RobOrderInterface {
        //抢单
        fun robOrder(index: Int)
    }
}